<template>
  <el-form ref="form" label-width="70px" style="padding: 10px;box-sizing: border-box;height: 100%">
      <el-form-item label="子类名称" class="mt">
          <el-input size="mini" v-model="childclass.name" placeholder="请输入产品或者项目的子类名称"></el-input>
      </el-form-item>
      <el-form-item label="子类类别">
          <el-radio-group v-model="childclass.type">
              <el-radio label="1">产品</el-radio>
              <el-radio label="2">项目</el-radio>
          </el-radio-group>
      </el-form-item>
      <el-form-item label="子类描述">
          <el-input type="textarea" size="mini" v-model="childclass.remarks" placeholder="请输入产品或者项目的子类描述"></el-input>
      </el-form-item>
      <el-row style="margin: 5px 0">
        <el-col :span="12" style="display: flex; justify-content: center;">
            <el-button @click.native="close" style="width:90%;display:block;">取消</el-button>
        </el-col>
        <el-col :span="12" style="display: flex; justify-content: center;">
            <el-button type="success" @click.native="submit" style="width:90%;display:block;" :loading="loading">保存</el-button>
        </el-col>
      </el-row>
  </el-form>
</template>
<script>
import C from '@/common/common.js'

export default {
  name: 'addUser',
  data () {
    return {
      childclass: {
        id: 0,
        name: '',
        type: '1',
        remarks: ''
      }
    }
  },
  methods: {
    submit: async function (index) {
      let that = this
      if (that.childclass.name === '') {
        C.error('请输入名称！')
        return false
      }
      let data = await C.ajax('/organization/subproconf/addedit', that.childclass, 'post')
      if (data) {
        if (data.errno === 0) {
          that.loading = false
          that.$notify({
            title: '成功',
            message: data.data,
            type: 'success'
          })
          C.closeBrowserWindow(data)
        } else {
          that.loading = false
          that.$notify.error({
            title: '错误',
            message: data.errmsg
          })
        }
      }
    },
    close: function () {
      C.closeBrowserWindow()
    }
  },
  mounted: async function () {
    let row = C.getDatas().row
    if (row) {
      this.childclass.id = row.id
      this.childclass.name = row.name
      this.childclass.type = row.type.toString()
      this.childclass.remarks = row.remarks
    }
  }
}
</script>
<style>
.el-input--mini .el-input__inner {
  height: 40px;
}
</style>